<?
     header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
     header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
     header ("Cache-Control: no-cache, must-revalidate");
     header ("Pragma: no-cache");
     
     header("content-type: application/x-javascript; charset=utf-8");
     
     $data=$_GET['data'];
     $val=$_GET['val'];

     
// 
include "connect/connect_dsccmis.php";

//mysql_pconnect($dbhost,$dbuser,$dbpass) or die ("Unable to connect to MySQL server");  
     //mysql_query("set names utf8");
     if ($data=='province') { 
          echo "<select name='province' onChange=\"dochange('amper', this.value);dochange('tumbon', '0');\">\n";
          echo "<option value='0'>==== เลือกจังหวัด ====</option>\n";
          $result=mysql_query("select prvid,substr(prvnme,9) as prvnme from codebook_dopa_province  where prvid in ('90','94','95','96') order by prvnme");
          while(list($id, $name)=mysql_fetch_array($result)){
		  	   if($val==$id){
               		echo "<option value=\"$id\" selected>$name</option> \n" ;
			   }else{
               		echo "<option value=\"$id\" >$name</option> \n" ;
			   }
          }
   } else if ($data=='provinceall') {
          echo "<select name='province' id='province' onChange=\"dochange('amper', this.value)\">\n";
          echo "<option value='0'>=== เลือกจังหวัด===</option>\n";
          $val2=$val;
          $val = substr($val,0,2);                                 
          $result=mysql_query("select prvid,substr(prvnme,9) as prvnme from codebook_dopa_province order by prvnme");
          while(list($id, $name)=mysql_fetch_array($result)){     
		  	   if($val2==$id){  
               	  echo "<option value=\"$id\" selected>$name</option> \n" ;
			   }else{
               	  echo "<option value=\"$id\" >$name</option> \n" ;
			   }
          }
     } else if ($data=='amper') {
          echo "<select name='amper' id='amper' onChange=\"dochange('tumbon', this.value)\">\n";
          echo "<option value='0'>=== เลือกอำเภอ ===</option>\n";
          $val2=$val;
          $val = substr($val,0,2);                                 
          $result=mysql_query("select distid,distnme from codebook_dopa_district  where left(distid,2)='$val' order by distnme");
          while(list($id, $name)=mysql_fetch_array($result)){     
		  	   if($val2==$id){  
               	  echo "<option value=\"$id\" selected>$name</option> \n" ;
			   }else{
               	  echo "<option value=\"$id\" >$name</option> \n" ;
			   }
          }
     } else if ($data=='tumbon') {
          echo "<select  name='tumbon' >\n";
          echo "<option value='0'>=== เลือกตำบล ===</option>\n";
          $val2=$val;
          $val = substr($val,0,4);
          $result=mysql_query("select subdistid,subdistnme from codebook_dopa_subdist where left(subdistid,4)='$val' order by subdistnme");
		  echo "select subdistid,subdistnme from codebook_dopa_subdist where left(subdistid,4)='$val1' order by subdistnme";
          while(list($id, $name)=mysql_fetch_array($result)){
		  	   if($val2==$id){  
               	echo "<option value=\"$id\" selected>$name</option> \n";
			   }else{
			    echo "<option value=\"$id\" >$name</option> \n";
			   }
          }
     }
     echo "</select>\n";  
?>